<?php
/**
 * Created by PhpStorm.
 * User: zzw
 * Date: 17-3-31
 * Time: 下午2:55
 */
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Board extends Modules_Controller
{

    function __construct()
    {
        parent::__construct();
        $this->rules = array(
            "rule" => array(

            )
        );

    }

    public function _edit_data()
    {
        $form=$this->input->post();
        $form['timeline'] = time();
        $form['industry'] = pinyin($form['name'],'UTF8',true);
        return $form;
    }
    public function copypro()
    {
        $ids = $this->input->post('ids');

        $rs=$this->model->get_one($ids);

        unset($rs['id']);
        unset($rs['sort_id']);
        unset($rs['timeline']);

        $id = $this->model->create($rs);
        if ($id) {
            $vdata['msg'] = '复制成功，请刷新查看';
            $vdata['status'] = 1;
        }else{
            $vdata['msg'] = '复制失败，请刷新后重试';
            $vdata['status'] = 0;
        }
        $this->output->set_content_type('application/json')->set_output(json_encode($vdata));
    }
    protected function _create_after($data){
        //  创建时生成链接

        // 保存关键词
        // 处理关键词，标题关键词，简介关键词，内容关键词
        if (isset($data['tags'])) {
            !!$data['tags'] and $this->mtags->add(str_replace(array('，',' ','　','|'), ',', $data['tags']),$this->cid,$data['id']);
        }
        $data['industry'] = pinyin($data['name'],'UTF8',true);
        // !!$data['title'] and $this->mtags->add(get_str_tags($data['title']),$this->cid,$data['id'],1);
        // !!$data['intro'] and $this->mtags->add(get_str_tags($data['intro']),$this->cid,$data['id'],2);
        // !!$data['content'] and $this->mtags->add(get_str_tags(html2txt($data['content'])),$this->cid,$data['id'],3);
    }
    /**
     * @brief 编辑结束后的处理
     */

    protected function _edit_after($data){
        // 保存关键词
        // 处理关键词，标题关键词，简介关键词，内容关键词
        if (isset($data['tags'])) {
            !!$data['tags'] and $this->mtags->add(str_replace(array('，',' ','　','|'), ',', $data['tags']),$this->cid,$data['id']);
        }

        // !!$data['title'] and $this->mtags->add(get_str_tags($data['title']),$this->cid,$data['id'],1);
        // !!$data['intro'] and $this->mtags->add(get_str_tags($data['intro']),$this->cid,$data['id'],2);
        // !!$data['content'] and $this->mtags->add(get_str_tags(html2txt($data['content'])),$this->cid,$data['id'],3);
    }
    protected function _create_data(){
        $form=$this->input->post();
        $form['timeline'] = time();
        $form['industry'] = pinyin($form['name'],'UTF8',true);
        return $form;
    }
    protected function _index_where(){
        $arr =array();
        if (isset($_GET['ctype']) && $_GET['ctype']) {
            $arr['ctype'] = $_GET['ctype'];
        }
        if (isset($_GET['name']) && $_GET['name']) {
            $arr['like'] = array('name',$_GET['name']);
        }
        return $arr;
    }
    public function import() {
        $files = $_FILES;
        if($files['file_excel']['tmp_name']) {
            $data = import_excel($files,'A,B,C');
            foreach($data as $ke=>$val) {
                //var_dump($val);die();
                if(!$val) continue;
                $insert = array(
                    'name'=>$val[0],
                    'short'=>$val[1],
                    'stock_code'=>$val[2],
                    'industry'=>pinyin($val[1],'UTF8',true),
                );
                $name = $this->model->get_one(array('name'=>$val[0]));
                $short = $this->model->get_one(array('short'=>$val[1]));
                $stock_code = $this->model->get_one(array('stock_code'=>$val[2]));
                if($name || $short || $stock_code) continue;
                $this->model->create($insert);
            }
        }

        redirect($_POST['ref']);
    }
}